package org.hyf.inspur.LessonDesin.clear.count6;

import org.hyf.inspur.LessonDesin.clear.tools.TProperties;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class CountProReducer extends Reducer<Text, Text, NullWritable,Text> {
    protected void reduce(Text key, Iterable<Text> values,
                          Reducer<Text, Text, NullWritable,Text>.Context context)
            throws IOException, InterruptedException {
        Iterator<Text> it=values.iterator();
        int count1=0;
        int count2=0;
        while(it.hasNext()){
            Text value=it.next();
            String str[]=value.toString().split(TProperties.getValue("fileoutsplit"));
            int num1 = Integer.parseInt(str[0]);
            int num2 = Integer.parseInt(str[1]);
            count1 = count1 + num1;
            count2 = count2 + num2;
            //int num=value.get();
            //count=count+num;
        }
        String str1[]=key.toString().split(TProperties.getValue("fileoutsplit"));
        String user=str1[0] + "|" + count1 + "|" + count2 + "|" + str1[1];
        //System.out.println(key +" count="+count);
        //context.write(new Text(key), new IntWritable(count));
        System.out.println(user);
        context.write(NullWritable.get(), new Text(user));
    }
}
